import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 导入ant和css样式 、 再use即可
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'

import * as Icons from '@ant-design/icons-vue'

import axios from 'axios';
import { Tool } from "@/utils/tool"; 

axios.defaults.baseURL = process.env.VUE_APP_SERVER;
//编写一个请求的过滤器【目的是在请求中携带token请求头】
/**
 * axios拦截器
 */
axios.interceptors.request.use(function (config) {
    console.log('请求参数：', config);
    const token = store.state.user.token;
    //判断当前user中的token是否不为空
    if (Tool.isNotEmpty(token)) {
        //将token赋值到请求头中
        config.headers.token = token;
        console.log("请求headers增加token:", token);
    }
    return config;
}, error => {
    return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
    console.log('返回结果：', response);
    return response;
}, error => {
    console.log('返回错误：', error);
    return Promise.reject(error);
})


const app = createApp(App);
app.use(store).use(router).use(Antd).mount('#app');

//全局使用图标
const icons: any = Icons;
for (const i in icons) {
    app.component(i, icons[i]);
}


console.log('环境:', process.env.NODE_ENV);
console.log('服务端:', process.env.VUE_APP_SERVER);